<!DOCTYPE html>
<script src='../resources/testharness.js'></script>
<script src='../resources/testharnessreport.js'></script>
<div id="log"></div>
<div id="host"></div>
<script>

var host = document.getElementById('host');

test(function() {
  var orphan1 = document.createElement('div');
  assert_false(orphan1.isConnected);
  host.appendChild(orphan1);
  assert_true(orphan1.isConnected);  
}, 'When detached, isConnected should be false. When inserted into a document tree, isConnected should be true.');

test(function() {
  host.attachShadow({mode: 'open'});
  var orphan2 = document.createElement('div');
  assert_false(orphan2.isConnected);
  host.shadowRoot.appendChild(orphan2);
  assert_true(orphan2.isConnected);
}, 'When inserted into a connected shadow tree, isConnected should be true.');

test(function() {
  var orphan3 = document.createElement('div');
  var host2 = document.createElement('div');
  host2.attachShadow({mode: 'open'});
  host2.shadowRoot.appendChild(orphan3);
  assert_false(host2.isConnected);
  assert_false(host2.shadowRoot.isConnected);
  assert_false(orphan3.isConnected);
}, 'When inserted into a detached tree, isConnected should be false.');

test(function() {
  var orphan4 = document.createElement('div');
  var host3 = document.createElement('div');
  var host4 = document.createElement('div');
  host3.attachShadow({mode: 'open'});
  host4.attachShadow({mode: 'open'});
  host4.shadowRoot.appendChild(orphan4);
  host3.shadowRoot.appendChild(host4);
  assert_false(host3.isConnected);
  assert_false(host3.shadowRoot.isConnected);
  assert_false(host4.isConnected);
  assert_false(host4.shadowRoot.isConnected);
  assert_false(orphan4.isConnected);
  host.appendChild(host3);
  assert_true(host3.isConnected);
  assert_true(host3.shadowRoot.isConnected);
  assert_true(host4.isConnected);
  assert_true(host4.shadowRoot.isConnected);
  assert_true(orphan4.isConnected);
}, 'When detached, isConnected should be false. When a shadow tree inserted into a document tree, isConnected should be true');

</script>
